package al238ProductExceptSelf;

import java.util.Arrays;

public class Prodoct {


    public static int[] productExceptSelf(int[] nums) {
        int length = nums.length;
        int[] answers = new int[length];

        answers[0] = 1;
        for(int i = 1;i<length;i++){
            answers[i] = answers[i-1] * nums[i-1];
        }
        int temp = 1;
        for(int i=length-2;i>=0;i--){
            temp *= nums[i+1];
            answers[i] *= temp;
        }
        return answers;
    }

    public static void main(String[] args) {
        int[] nums = {-1,1,0,-3,3};
        int[] answers = productExceptSelf(nums);
        System.out.println(Arrays.toString(answers));
    }
}
